﻿Imports System.Data.SqlClient

Public Class adm_editCategory
    Inherits System.Web.UI.Page
    Private sSQL As String
    Private objfind As New GetData
    Private objrd As SqlDataReader = Nothing
    Private ps As New PreparedStatement(sSQL)
    Dim strErr As String = ""
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim strCID, strEname As String
        Dim HTMLString As String = ""
        If (Session("admin_ID") <> Nothing And Session("admin_ID") <> "") Then
            strCID = Trim(Request("aid"))
            ps.addParameter("id", strCID)
            If Request("btnUpdate") <> Nothing And Request("btnUpdate") = "Update" Then
                Exit Sub
            End If
            sSQL = "select * from Category where Category_ID=@id"
            ps.strSql = sSQL
            Dim conn As SqlConnection = objfind.getConn()

            objrd = objfind.dr(ps, strErr, conn, objrd)
            If objrd.HasRows Then
                While (objrd.Read())
                    strEname = objrd("Category_Name").ToString
                    CID.Text = strCID
                    Ename.Text = strEname
                End While
            End If
            objfind.closeConn(conn)

        Else
            Response.Redirect("../adm_login.aspx")
        End If
    End Sub

    Protected Sub btnCancel_Click(sender As Object, e As EventArgs) Handles btnCancel.Click
        Response.Redirect("adm_findCategory.aspx")
    End Sub

    Private Sub btnUpdate_Click(sender As Object, e As System.EventArgs) Handles btnUpdate.Click
        If Ename.Text = "" Then
            result.InnerHtml = ""
            result.InnerHtml = "<center><b><font color=""#FF0000""> Please enter your Category name</font></b></center>"
            Exit Sub
        End If
        sSQL = "update Category set Category_Name=@ename where Category_ID=@id"
        ps.strSql = sSQL
        ps.addParameter("ename", Ename.Text)
        objfind.es(ps, strErr)
        If strErr = Nothing Or strErr = "" Then
            result.InnerHtml = ""
            result.InnerHtml = "<center><b><font color=""#FF0000""> Update Category Success！</font></b></center>"
        Else
            result.InnerHtml = ""
            result.InnerHtml = "<center><b><font color=""#FF0000"">Error！</font></b><p>" & strErr & "</p></center>"
        End If
    End Sub
End Class